import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:ios_system_permission/ios_permission_status.dart';

import 'ios_system_permission_platform_interface.dart';

/// An implementation of [IosSystemPermissionPlatform] that uses method channels.
class MethodChannelIosSystemPermission extends IosSystemPermissionPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('ios_system_permission');

  @override
  Future<PermissionStatus?> getContactPermission() async {
    final status =
        await methodChannel.invokeMethod<int>('getContactPermission');
    return PermissionStatus.getStatus(status!);
  }

  @override
  Future<PermissionStatus?> getPhotoPermission() async {
    final status = await methodChannel.invokeMethod<int>('getPhotoPermission');
    return PermissionStatus.getStatus(status!);
  }

  @override
  Future<PermissionStatus?> getTrackingPermission() async {
    final status =
        await methodChannel.invokeMethod<int>('getTrackingPermission');
    return PermissionStatus.getStatus(status!);
  }

  @override
  Future<PermissionStatus?> requestContactPermission() async {
    final status =
        await methodChannel.invokeMethod<int>('requestContactPermission');
    return PermissionStatus.getStatus(status!);
  }

  @override
  Future<PermissionStatus?> requestPhotoPermission() async {
    final status =
        await methodChannel.invokeMethod<int>('requestPhotoPermission');
    return PermissionStatus.getStatus(status!);
  }

  @override
  Future<PermissionStatus?> requestTrackingPermission() async {
    final status =
        await methodChannel.invokeMethod<int>('requestTrackingPermission');
    return PermissionStatus.getStatus(status!);
  }
}
